module.exports = function (app) {
	return new ChatRemote(app);
};

var ChatRemote = function (app) {
	this.app = app;
	this.channelService = app.get('channelService');
};

ChatRemote.prototype.add = function (uid, sid, cid, cb) {
	console.log("ChatRemote.prototype.add: uid is %s, sid is %s, cid is %s.", uid, sid, cid);
	var channel = this.channelService.getChannel(cid, true);
	channel.add(uid, sid);
	var users = channel.getMembers();
	cb(users);
	channel.pushMessage({ route: "onEnter", uid: uid });
};

/**
 * 移除玩家
 */
ChatRemote.prototype.remove = function (uid, sid, cid, cb) {
	var channel = this.channelService.getChannel(cid, false);
	// leave channel
	if (!!channel) {
		channel.leave(uid, sid);
	}
	channel.pushMessage({ route: "onLeave", uid: uid });
	cb();
};
